﻿// -----------------------------------------------------------------------
// <copyright file="InvalidPushAppException.cs" company="Zen Design Corp">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace Zen.BlackBerry.Push.AppManagement
{
	using System;
	using System.Runtime.Serialization;
	using Zen.BlackBerry.Common;

	/// <summary>
	/// Exception thrown when a push request cannot be found in the persistent
	/// store or a push request with the specified id already exists in the
	/// persistent store.
	/// </summary>
	public class InvalidPushAppException : PushSDKException
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="InvalidPushAppException"/> class.
		/// </summary>
		public InvalidPushAppException()
		{
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="InvalidPushAppException"/> class.
		/// </summary>
		/// <param name="errorCode">The error code.</param>
		public InvalidPushAppException(InvalidPushAppErrorCode errorCode)
			: base(string.Format("Error code={0}", errorCode.ToString()))
		{
			ErrorCode = errorCode;
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="InvalidPushAppException"/> class.
		/// </summary>
		/// <param name="errorCode">The error code.</param>
		/// <param name="message">The message.</param>
		public InvalidPushAppException(InvalidPushAppErrorCode errorCode, string message)
			: base(string.Format("{1}\n\tError code={0}", errorCode.ToString(), message))
		{
			ErrorCode = errorCode;
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="InvalidPushAppException"/> class.
		/// </summary>
		/// <param name="errorCode">The error code.</param>
		/// <param name="innerException">The inner exception.</param>
		public InvalidPushAppException(InvalidPushAppErrorCode errorCode, Exception innerException)
			: base(string.Format("Error code={0}", errorCode.ToString()), innerException)
		{
			ErrorCode = errorCode;
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="InvalidPushAppException"/> class.
		/// </summary>
		/// <param name="errorCode">The error code.</param>
		/// <param name="message">The message.</param>
		/// <param name="innerException">The inner exception.</param>
		public InvalidPushAppException(InvalidPushAppErrorCode errorCode, string message, Exception innerException)
			: base(string.Format("{1}\n\tError code={0}", errorCode.ToString(), message), innerException)
		{
			ErrorCode = errorCode;
		}

		/// <summary>
		/// Initializes a new instance of the <see cref="InvalidPushAppException"/> class.
		/// </summary>
		/// <param name="info">The object that holds the serialized object data.</param>
		/// <param name="context">The contextual information about the source or destination.</param>
		public InvalidPushAppException(SerializationInfo info, StreamingContext context)
			: base(info, context)
		{
			ErrorCode = (InvalidPushAppErrorCode)info.GetValue("errorCode", typeof(InvalidPushAppErrorCode));
		}

		/// <summary>
		/// Gets the error code.
		/// </summary>
		/// <value>The error code.</value>
		public InvalidPushAppErrorCode ErrorCode
		{
			get;
			private set;
		}

		/// <summary>
		/// When overridden in a derived class, sets the <see cref="T:System.Runtime.Serialization.SerializationInfo"/> with information about the exception.
		/// </summary>
		/// <param name="info">The <see cref="T:System.Runtime.Serialization.SerializationInfo"/> that holds the serialized object data about the exception being thrown.</param>
		/// <param name="context">The <see cref="T:System.Runtime.Serialization.StreamingContext"/> that contains contextual information about the source or destination.</param>
		/// <exception cref="T:System.ArgumentNullException">The <paramref name="info"/> parameter is a null reference (Nothing in Visual Basic). </exception>
		/// <PermissionSet>
		/// 	<IPermission class="System.Security.Permissions.FileIOPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Read="*AllFiles*" PathDiscovery="*AllFiles*"/>
		/// 	<IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="SerializationFormatter"/>
		/// </PermissionSet>
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
		{
			base.GetObjectData(info, context);
			info.AddValue("errorCode", ErrorCode);
		}
	}
}
